from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS "tb_system_visitors" (
    "id" UUID NOT NULL  PRIMARY KEY,
    "active" BOOL   DEFAULT True,
    "created_at" TIMESTAMPTZ   DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ   DEFAULT CURRENT_TIMESTAMP,
    "ip" VARCHAR(255) NOT NULL,
    "country" VARCHAR(255) NOT NULL,
    "region" VARCHAR(255) NOT NULL,
    "city" VARCHAR(255) NOT NULL,
    "count" INT NOT NULL  DEFAULT 0
);
COMMENT ON COLUMN "tb_system_visitors"."ip" IS 'IP 地址';
COMMENT ON COLUMN "tb_system_visitors"."country" IS '国家';
COMMENT ON COLUMN "tb_system_visitors"."region" IS '地区';
COMMENT ON COLUMN "tb_system_visitors"."city" IS '城市';
COMMENT ON COLUMN "tb_system_visitors"."count" IS '访问次数';"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        DROP TABLE IF EXISTS "tb_system_visitors";"""
